//
//  GJFPlotDetailToolView.m
//  Wedding
//
//  Created by 郭静芬 on 2016/12/23.
//  Copyright © 2016年 郭静芬. All rights reserved.
//

#import "GJFToolView.h"

@interface GJFToolView ()
@property (nonatomic, strong) UIButton *zanBtn;
@property (nonatomic, strong) UIButton *collectBtn;
@property (nonatomic, strong) UIButton *telBtn;
@end

@implementation GJFToolView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];

        UIView *line1 = [[UIView alloc] init];
        line1.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:line1];
        [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.mas_equalTo(self).mas_offset(0);
            make.height.mas_equalTo(0.5);
        }];
        
        int maginTop = 12;
        [self.zanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(maginTop);
            make.left.mas_equalTo(self).mas_offset(15);
            make.size.mas_equalTo(CGSizeMake(WIDTH / 6 - 40, self.frame.size.height - maginTop * 2));
        }];
        
        UIView *line0 = [[UIView alloc] init];
        line0.backgroundColor = HOMECOLOR;
        [self addSubview:line0];
        [line0 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(10);
            make.left.mas_equalTo(self.mas_left).mas_offset(WIDTH / 6 - 0.5);
            make.size.mas_equalTo(CGSizeMake(1, self.frame.size.height - 20));
        }];
        
        [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(maginTop);
            make.left.mas_equalTo(self.zanBtn.mas_right).mas_offset(45);
            make.size.mas_equalTo(CGSizeMake(WIDTH / 6 - 40, self.frame.size.height - maginTop * 2));
        }];
        
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = HOMECOLOR;
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(10);
            make.left.mas_equalTo(self.mas_left).mas_offset(WIDTH / 3 - 0.5);
            make.size.mas_equalTo(CGSizeMake(1, self.frame.size.height - 20));
        }];
        
        [self.telBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(maginTop);
            make.left.mas_equalTo(self.collectBtn.mas_right).mas_offset(45);
            make.size.mas_equalTo(CGSizeMake(WIDTH / 6 - 40, self.frame.size.height - maginTop * 2));
        }];
        
        [self.orderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(0);
            make.right.mas_equalTo(self).mas_offset(0);
            make.width.mas_equalTo(WIDTH / 2);
            make.height.mas_equalTo(self.frame.size.height);
        }];
    }
    return self;
}

#pragma mark - setter方法 - 更改点赞按钮的状态
- (void)setPlotModel:(GJFPlotModel *)plotModel {
    _plotModel = plotModel;
    self.zanBtn.selected = [plotModel.is_zan boolValue];
    self.collectBtn.selected = [plotModel.is_collect boolValue];
}

#pragma mark - 赞按钮触发方法
- (void)zanAction {
    if (_delegate && [_delegate respondsToSelector:@selector(clickZanBtnAction)]) {
        [_delegate clickZanBtnAction];
    }
}
#pragma mark - 收藏按钮触发方法
- (void)collectAction {
    if (_delegate && [_delegate respondsToSelector:@selector(clickCollectBtnAction)]) {
        [_delegate clickCollectBtnAction];
    }
}
#pragma mark - 预约商家按钮触发方法
- (void)oderAction {
    if (_delegate && [_delegate respondsToSelector:@selector(clickOrderBtnAction)]) {
        [_delegate clickOrderBtnAction];
    }
}
#pragma mark - 电话按钮触发方法
- (void)telAction {
    if (_delegate && [_delegate respondsToSelector:@selector(clickTelBtnAction)]) {
        [_delegate clickTelBtnAction];
    }
}

#pragma mark - 懒加载

- (UIButton *)zanBtn {
    if (!_zanBtn) {
        _zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_zanBtn setBackgroundImage:[UIImage imageNamed:@"icon-点赞"] forState:UIControlStateNormal];
        [_zanBtn setBackgroundImage:[UIImage imageNamed:@"icon-点赞-已使用"] forState:UIControlStateSelected];
        [_zanBtn addTarget:self action:@selector(zanAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_zanBtn];
    }
    return _zanBtn;
}

- (UIButton *)collectBtn {
    if (!_collectBtn) {
        _collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_collectBtn setBackgroundImage:[UIImage imageNamed:@"icon-收藏"] forState:UIControlStateNormal];
        [_collectBtn setBackgroundImage:[UIImage imageNamed:@"icon-收藏-已使用"] forState:UIControlStateSelected];
        [_collectBtn addTarget:self action:@selector(collectAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_collectBtn];
    }
    return _collectBtn;
}

- (UIButton *)orderBtn {
    if (!_orderBtn) {
        _orderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _orderBtn.backgroundColor = HOMECOLOR;
        [_orderBtn setTitle:@"预约商家" forState:UIControlStateNormal];
        [_orderBtn addTarget:self action:@selector(oderAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_orderBtn];
    }
    return _orderBtn;
}

- (UIButton *)telBtn {
    if (!_telBtn) {
        _telBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_telBtn addTarget:self action:@selector(telAction) forControlEvents:UIControlEventTouchUpInside];
        [_telBtn setBackgroundImage:[UIImage imageNamed:@"icon-电话"] forState:UIControlStateNormal];
        [self addSubview:_telBtn];

    }
    return _telBtn;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
